$(function(){
	$("#VendorSpinner").change(function(){
		var id = $("#VendorSpinner").val();
		location.href = projectName+"/bill.do?method=2&id="+id;
		/*$.ajax({
			type:"POST",
			url:projectName+"/bill.do",
			dataType:"json",
			contentType:"application/x-www-form-urlencoded; charset=utf-8",
			async:false,
			data:"method=2&id="+id,
			success:function(data){
				location.reload();
			},
			error:function(){
				
			}
		});*/
	});

	$.ajax({
		type:"POST",
		url:"SystemConfig",
		data:"method=7",
		dataType:"json",
		contentType:"application/x-www-form-urlencoded; charset=utf-8",
		success:function(data){
			var src = "<option value='0'>供货商</option>";
			for(var count in data){
					src += "<option value='"+data[count].id+"'>"+data[count].vendor+"</option>";
				}
				$("#VendorSpinner").html(src);
				if(vendorIds != undefined && vendorIds != "" && vendorIds != null){
					$("#VendorSpinner").val(vendorIds);
				}
				
			},
			error:function(data){
				alert("error:"+data);
			}
		});
});
function toDataPage(currentPage){
	var id = $("#VendorSpinner").val();
	location.href = projectName+"/bill.do?method=2&id="+id+"&currentPage="+currentPage;
}

$(function(){
	$("#addbill").click(function(){
		$.ajax({
			type:"POST",
			url:"SystemConfig",
			data:"method=7",
			dataType:"json",
			contentType:"application/x-www-form-urlencoded; charset=utf-8",
			success:function(data){
				var src = "<option value='0'>供货商</option>";
				for(var count in data){
					src += "<option value='"+data[count].id+"'>"+data[count].vendor+"</option>";
				}
				$("#VendorSpinner1").html(src);
			},
			error:function(data){
				alert("error:"+data);
			}
		});
		
		$(".choice-checkbox").click(function(){
			var total = 0;
			$(".choice-checkbox").each(function(i,e){
				var a = 0;
				if($(e).is(':checked')){
					a = parseInt($(e).parent().parent().find("td").find(".input-amount").val());
					total = total + a;
				}else{
					
				}
			});
			$("#Total").val(total);
		});
		
		$("#addNewBill").click(function(){
			var vendorId = $("#VendorSpinner1").val();
			var billDate = $("#Date").val();
			var billDueDate = $("#DueDate").val();
			var total = $("#Total").val();
			$.ajax({
				type:"POST",
				url:"SystemConfig",
				dataType:"json",
				contentType:"application/x-www-form-urlencoded; charset=utf-8",
				async:false,
				data:"method=10&vendorId="+vendorId+"&billDate="+billDate+"&billDueDate="+billDueDate+"&total="+total,
				success:function(data){
					location.reload();
					alert("添加成功");
				},
				error:function(){
					alert("添加失败");
				}
			});
		});
		$("#btnReset").click(function(){
			$("#VendorSpinner1").val("0");
			$("#Date").val("");
			$("#DueDate").val("");
			$("#Total").val("");
			$(".input-amount").val("");
			$(".choice-checkbox").val("");
		});
	});
});

$(function(){
	$("#addbtnCreate").click(function(){
		var vendor = $("#Name2").val();
		var vendorAddress = $("#Address2").val();
		var vendorPhone = $("#Phone2").val();
		var vendorFax = $("#FAX2").val();
		var contactPerson = $("#Contact2").val();
		$.ajax({
			type:"POST",
			url:"SystemConfig",
			dataType:"json",
			contentType:"application/x-www-form-urlencoded; charset=utf-8",
			async:false,
			data:"method=8&vendor="+vendor+"&vendorAddress="+vendorAddress+"&vendorPhone="+vendorPhone+"&vendorFax="+vendorFax+"&contactPerson="+contactPerson,
			success:function(data){
				location.reload();
				alert("添加成功");
			},
			error:function(){
				alert("添加失败");
			}
		});
		
	});
	
	$("#VendorbtnReset").click(function(){
		$("#Name2").val("");
		$("#Address2").val("");
		$("#Phone2").val("");
		$("#FAX2").val("");
		$("#Contact2").val("");
	});
});